/*
 * @(#)ExamImpl.java Time: 2013-2-27
 *
 * Copyright 2013 xuedou.com All rights reserved.
 */
package xuedou.skymoni.impl;

import java.rmi.RemoteException;
import java.util.List;

import javax.xml.rpc.ServiceException;

import org.tempuri.WmgwLocator;

import xuedou.skymoni.bean.Exam;
import xuedou.skymoni.bean.Examnum;
import xuedou.skymoni.bean.Examschool;
import xuedou.skymoni.bean.Examtime;
import xuedou.skymoni.dao.ExamDAO;
import xuedou.skymoni.service.ExamService;

/**
 *<pre>类说明</pre>
 *<b>功能描述：</b>
 * 报名考试Impl
 * @author  jinmingming jinmingming@xuedou.com
 * @version 1.0, 2013-2-27
 */
public class ExamImpl implements ExamService{
	
	ExamDAO examDAO = new ExamDAO();

	@Override
	public boolean addExam(Exam exam) {
//		return examDAO.addExam(exam);
		return examDAO.addExamSecond(exam);
	}
	
	@Override
	public List getStuCountBySchool(String examschool,String examnum){
		return examDAO.getStuCountBySchool(examschool,examnum);
	}
	

	@Override
	public int allCount(String examnum,String schoolName) {
		return examDAO.allCount(examnum,schoolName);
	}

	@Override
	public Exam findByNameTelIsSky(String name,String examnum,String snumber) {
		return examDAO.findByNameTelIsSky(name,examnum,snumber);
	}
	
	@Override
	public Exam findByNameTel(String name,String tel,String examnum){
		return examDAO.findByNameTel(name, tel, examnum);
	}

	@Override
	public boolean updateSendcount(int id) {
		return examDAO.updateSendcount(id);
	}

	@Override
	public String[] schoolMsg(String examschool) {
		String schoolAddress ="";
		String schoolTel = "";
		if(examschool.equals("园岭")){
			schoolAddress = "福田区红荔路2002号园岭大厦1-2楼（市妇儿医院左侧）";
			schoolTel = "83242005，83242006";
		}else if(examschool.equals("莲花北")){
			schoolAddress = "福田区莲花北小区富莲大厦裙楼2栋2楼（海王星辰楼上）";
			schoolTel = "83088522，83088722";
		}else if(examschool.equals("香蜜湖")){
			schoolAddress = "福田区农林路与红荔西路交汇处荔林苑万家乐百货二楼";
			schoolTel = "83693602，83699469";
		}else if(examschool.equals("翠竹")){                                       
			schoolAddress = "罗湖区文锦中路2092号怡泰大厦二楼（翠园中学高中部左侧）"; 
			schoolTel = "88861066，25601637";
		}else if(examschool.equals("益田")){
			schoolAddress = "福田区福强路中港城5楼";
			schoolTel = "83829211，83828177";
		}else if(examschool.equals("景田")){
			schoolAddress = "福田区景田西路赛格景苑裙楼二楼";
			schoolTel = "83934011，83934012";
		}
		//String msg = "校区地址："+schoolAddress+"，校区电话："+schoolTel+"！";
		String[] msg = new String[]{schoolAddress,schoolTel};
		return msg;
	}

	@Override
	public String sendMsg(String tel, String content) {
		String msg = "";
		WmgwLocator wmgwLocator = new WmgwLocator();
		String strArgs[] = new String[10];
		strArgs[0] = "J00333"; // 用户名
		strArgs[1] = "147258"; // 密码
		strArgs[2] = tel;// 手机号
		strArgs[3] = content;
		strArgs[4] = "1"; // 手机号码个数
		strArgs[5] = "*"; // 子端口
		String strMsg = null;
		strMsg = strArgs[3];
		try {
			msg = wmgwLocator.getwmgwSoap().mongateCsSpSendSmsNew(
									strArgs[0], strArgs[1], strArgs[2], strMsg,
									Integer.valueOf(strArgs[4]).intValue(),
									strArgs[5]);
			
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		return msg;
	}

	@Override
	public List<Exam> allExam() {
		return examDAO.allExam();
	}

	@Override
	//需要修改
	public boolean getStuCountBySchoolTime(String examschool, String examtime,String examnum) {
//		int count =  examDAO.getStuCountBySchoolTime(examschool, examtime,examnum);
		int count=examDAO.getStuCountBySchool(examschool, examtime,examnum);//已经报了多少名
		int countsecond=examDAO.getStuCountBySchool_newexamschool(examschool, examtime, examnum);
		System.out.println("exam表中校区："+examschool+"有："+count+"人报名");
		System.out.println("newexamschool表中校区："+examschool+"有："+countsecond+"人报名");
		
		boolean flag = false;
		int classsize = examDAO.findClasssize(examschool);
		
		if(count>=classsize){
			flag = false;//已满
		}else{
			flag = true;//未满
		}
		return flag;
		/*if(examschool.equals("园岭") && count >= 20){return false;
		}else if(examschool.equals("莲花北") && count >= 20){return false;
		}else if(examschool.equals("香蜜湖") && count >= 5){return false;
		}else if(examschool.equals("翠竹") && count >= 21){return false;
		}else if(examschool.equals("益田") && count >= 11){return false;
		}else if(examschool.equals("景田") && count >= 13){return false;
		}else{return true;}*/
	}

	@Override
	public List<Examnum> allExamnum() {
		return examDAO.allExamnum();
	}

	@Override
	public boolean updateExamnum(int id, String flag) {
		return examDAO.updateExamnum(id, flag);
	}

	@Override
	public String isOpen(String changci) {
		return examDAO.isOpen(changci);
	}
	
	@Override
	public String isSky(String cname){
		return examDAO.isSky(cname);
	}

	@Override
	public boolean updateConfigure(String cname, String cvalue) {
		return examDAO.updateConfigure(cname, cvalue);
	}

	@Override
	public String[] selectScore(String sname, String ticknum,String examnum) {
		return examDAO.selectScore(sname, ticknum,examnum);
	}

	@Override
	public Exam ispayment(String ticknum, String examnum) {
		return examDAO.ispayment(ticknum, examnum);
	}

	@Override
	public boolean updateIspayment(int id, String ispayment) {
		return examDAO.updateIspayment(id, ispayment);
	}

	@Override
	public List<Examtime> allExamtime() {
		return examDAO.allExamtime();
	}

	@Override
	public List<Examschool> allExamschool() {
//		return examDAO.allExamschool();
		return examDAO.allExamschoolSecond();
	}

	@Override
	public int findClasssize(String eschool) {
		return examDAO.findClasssize(eschool);
	}

	@Override
	public boolean getStuCountBySchool(String examschool, String examtime,
			String examnum) {
//		return examDAO.getStuCountBySchool(examschool, examtime, examnum);
		// TODO Auto-generated method stub
		return false;
	}


//	public boolean isOpen() {
//		// TODO Auto-generated method stub
//		boolean temp=examDAO.isOpen("布外模考");
//		return temp;
//	}
	
}
